
from elasticsearch import Elasticsearch
 
es = Elasticsearch(hosts=[{"host":'127.0.0.1', "port": 9200}])
#es.indices.create(index='article', ignore=400)
 
data = {'content':"在北京学习python"}
# result = es.create(index='article',body=data)
# print(result)

# data = {'title':"你好",'url': 'http://123.com',"content":"你好123"}

# result = es.index(index='article',body=data)

# print(result)

#修改
#result = es.index(index='article',body=data, id='GyJgb3MBuQaE6wYOApTh')
#result = es.update(index='article',body=data,id='GyJgb3MBuQaE6wYOApTh')
#print(result)

#删除
# result = es.delete(index='article',id='GyJgb3MBuQaE6wYOApTh')
# print(result)


#查询
result = es.search(index='article')
print(result)


# mapping = {
#     'query': {
#         'match': {
#             'content': '学习 北京'
#         }
#     }
# }

# result = es.search(index='article',body=mapping)
# print(result)